set(LIBCXXABI_SOURCE_DIR ${ClickHouse_SOURCE_DIR}/contrib/libcxxabi)
set(LIBCXX_SOURCE_DIR ${ClickHouse_SOURCE_DIR}/contrib/libcxx)
#set(LIBCXXABI_BINARY_DIR ${ClickHouse_BINARY_DIR}/contrib/libcxxabi)

set(SRCS
${LIBCXXABI_SOURCE_DIR}/src/stdlib_stdexcept.cpp
${LIBCXXABI_SOURCE_DIR}/src/cxa_virtual.cpp
${LIBCXXABI_SOURCE_DIR}/src/cxa_thread_atexit.cpp
${LIBCXXABI_SOURCE_DIR}/src/fallback_malloc.cpp
#${LIBCXXABI_SOURCE_DIR}/src/cxa_noexception.cpp
${LIBCXXABI_SOURCE_DIR}/src/cxa_guard.cpp
${LIBCXXABI_SOURCE_DIR}/src/cxa_default_handlers.cpp
${LIBCXXABI_SOURCE_DIR}/src/cxa_personality.cpp
${LIBCXXABI_SOURCE_DIR}/src/stdlib_exception.cpp
${LIBCXXABI_SOURCE_DIR}/src/abort_message.cpp
${LIBCXXABI_SOURCE_DIR}/src/cxa_demangle.cpp
${LIBCXXABI_SOURCE_DIR}/src/cxa_unexpected.cpp
${LIBCXXABI_SOURCE_DIR}/src/cxa_exception.cpp
${LIBCXXABI_SOURCE_DIR}/src/cxa_handlers.cpp
${LIBCXXABI_SOURCE_DIR}/src/cxa_exception_storage.cpp
${LIBCXXABI_SOURCE_DIR}/src/private_typeinfo.cpp
${LIBCXXABI_SOURCE_DIR}/src/stdlib_typeinfo.cpp
${LIBCXXABI_SOURCE_DIR}/src/cxa_aux_runtime.cpp
${LIBCXXABI_SOURCE_DIR}/src/cxa_vector.cpp
${LIBCXXABI_SOURCE_DIR}/src/stdlib_new_delete.cpp
)

add_library(cxxabi_static ${SRCS})

target_include_directories(cxxabi_static PUBLIC ${LIBCXXABI_SOURCE_DIR}/include ${LIBCXX_SOURCE_DIR}/include)
target_compile_definitions(cxxabi_static PRIVATE -D_LIBCPP_BUILDING_LIBRARY)
target_compile_options(cxxabi_static PRIVATE -nostdinc++ -fno-sanitize=undefined) # If we don't disable UBSan, infinite recursion happens in dynamic_cast.


